# Copyright (c) 2008 Alvin Wang http://cloudwizard.com/
# License New BSD
# See README for additional information
"""
Amazon Web Services Cloud Support

"""
from cloudwizard.storage import StorageService
from cloudwizard.storage import StorageDevice
from cloudwizard.config import Config
from boto.s3.connection import S3Connection
import os

class S3( StorageService):
    

    def __init__(self, auth=None, username='default'):
        if auth:
            self.cloud_auth=auth
        else:
            self.cloud_auth = Config( cloud_abbrev = 'aws', config_name=username)
        self.cloud_obj = S3Connection( self.cloud_auth.data['aws_access_id'], \
            self.cloud_auth.data['aws_secret_key'])


    def create(self, bucket_name=None):
        bucket = self.cloud_obj.create_bucket(bucket_name)

    def olist(self, *args):
        rs = self.cloud_obj.get_all_buckets()
        return rs

    def plist(self, *args):
        rs = self.olist()
        for b in rs:
            print b.name

class Bucket( StorageDevice):
    def __init__(self, auth=None, username='default'):
        if auth:
            self.cloud_auth=auth
        else:
            self.cloud_auth = Config( cloud_abbrev = 'aws', config_name=username)
        self.cloud_obj = EC2Connection( self.cloud_auth.data['aws_access_id'], \
            self.cloud_auth.data['aws_secret_key'])